<!DOCTYPE html
	PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport"
		content="width=device-width, initial-scale=1.0 ,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">

	<title>结算页面</title>

	<link href="../AmazeUI-2.4.2/assets/css/amazeui.css" rel="stylesheet" type="text/css" />

	<link href="../basic/css/demo.css" rel="stylesheet" type="text/css" />
	<link href="../css/cartstyle.css" rel="stylesheet" type="text/css" />

	<link href="../css/jsstyle.css" rel="stylesheet" type="text/css" />

	<script type="text/javascript" src="../js/address.js"></script>
	<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.6/vue.min.js"></script>
	<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.19.2/axios.min.js"></script>
	<script src="../js/axiosUtil.js"></script>
	<style>
		.goodImg {
			height: 80px;
			width: 80px;
		}
	</style>
</head>

<body>

	<div id="app1">
		<!--顶部导航条 -->
		<div class="am-container header">
			<ul class="message-l">
				<div class="topMessage">
					<template v-if="!islogin">
						<div class="menu-hd">
							<a href="login.html" target="_top" class="h">亲，请登录</a>
							<a href="register.html" target="_top">免费注册</a>
						</div>
					</template>
					<template v-else>
						<div class="menu-hd">
							<a href="#" style="color: red;">{{username}}</a>
							<a href="#" @click="logout">退出登录</a>
						</div>
					</template>
				</div>
			</ul>
			<ul class="message-r" v-if="islogin">
				<div class="topMessage home">
					<div class="menu-hd"><a href="home.html" target="_top" class="h">商城首页</a></div>
				</div>
				<template v-if="islogin">
					<div class="topMessage my-shangcheng">
						<div class="menu-hd MyShangcheng"><a href="information.html" target="_top"><i
									class="am-icon-user am-icon-fw"></i>个人中心</a></div>
					</div>
					<div class="topMessage mini-cart">
						<div class="menu-hd"><a id="mc-menu-hd" href="shopcart.html" target="_top"><i
									class="am-icon-shopping-cart  am-icon-fw"></i><span>购物车</span><strong
									id="J_MiniCartNum" class="h">0</strong></a></div>
					</div>
				</template>
			</ul>
		</div>

		<!--悬浮搜索框-->

		<div class="nav white">
			<div class="logo"><img src="../images/logo.png" /></div>
			<div class="logoBig">
				<li><img src="../images/logobig.png" /></li>
			</div>

			<div class="search-bar pr">
				<a name="index_none_header_sysc" href="#"></a>
				<form onsubmit="return false;">
					<input id="searchInput" name="index_none_header_sysc" type="text" placeholder="搜索"
						autocomplete="off" v-model="name">
					<input id="ai-topsearch" class="submit am-btn" value="搜索" index="1" type="button" @click="search">
				</form>
			</div>
		</div>
	</div>

	<div class="clear"></div>
	<div class="concent">
		<!--地址 -->
		<div class="paycont" id="app2">
			<div class="address">
				<h3>确认收货地址 </h3>
				<div class="control">
					<div class="tc-btn createAddr theme-login am-btn am-btn-danger" v-if="addResstableData.length<3">添加新地址</div>
				</div>
				<div class="clear"></div>
				<ul>
					<template v-for="(item,index) in addResstableData" :key="index">
						<div class="per-border"></div>
						<li class="user-addresslist defaultAddr">

							<div class="address-left">
								<div class="user DefaultAddr">

									<span class="buy-address-detail">
										<span class="buy-user">{{item.receiverName}} </span>
										<span class="buy-phone">{{item.receiverPhone}}</span>
									</span>
								</div>
								<div class="default-address DefaultAddr">
									<span class="buy-line-title buy-line-title-type">收货地址：</span>
									<span class="buy--address-detail">
										{{item.receiverAddress}}
									</span>

									</span>
								</div>
								<ins :class="item.id===id?'deftip':'deftip hidden'">默认地址</ins>
							</div>
							<div class="address-right">
								<a href="../person/address.html">
									<span class="am-icon-angle-right am-icon-lg"></span></a>
							</div>
							<div class="clear"></div>

							<div class="new-addr-btn">
								<a href="#" :class="item.id===id?'hidden':''" @click.prevent="setAddr(item.id,index)">设为默认</a>
							</div>

						</li>

					</template>

				</ul>

				<div class="clear"></div>
			</div>


			<!--订单 -->
			<div class="concent">
				<div id="payTable">
					<h3>确认订单信息</h3>
					<div class="cart-table-th">
						<div class="wp">

							<div class="th th-item">
								<div class="td-inner">商品信息</div>
							</div>
							<div class="th th-price">
								<div class="td-inner">单价</div>
							</div>
							<div class="th th-amount">
								<div class="td-inner">数量</div>
							</div>
							<div class="th th-sum">
								<div class="td-inner">金额</div>
							</div>
							<div class="th th-oplist">
								<div class="td-inner">配送方式</div>
							</div>

						</div>
					</div>
					<div class="clear"></div>

					<template v-for="(item,index) in orderDate" :key="index">
						<tr class="item-list" >
							<div class="bundle  bundle-last">

								<div class="bundle-main">
									<ul class="item-content clearfix">
										<div class="pay-phone">
											<li class="td td-item">
												<div class="item-pic">
													<a href="#" class="J_MakePoint">
														<img :src="item.productImage"
															class="itempic J_ItemImg goodImg"></a>
												</div>
												<div class="item-info">
													<div class="item-basic-info">
														<a href="#" class="item-title J_MakePoint"
															data-point="tbcart.8.11">{{item.productName}}</a>
													</div>
												</div>
											</li>
											<li class="td td-price">
												<div class="item-price price-promo-promo">
													<div class="price-content">
														<em class="J_Price price-now">{{item.currentUnitPrice}}</em>
													</div>
												</div>
											</li>
										</div>
										<li class="td td-amount">
											<div class="amount-wrapper ">
												<div class="item-amount ">
													<span class="phone-title">购买数量</span>
													<div class="sl">
														{{item.quantity}}
													</div>
												</div>
											</div>
										</li>
										<li class="td td-sum">
											<div class="td-inner">
												<em tabindex="0" class="J_ItemSum number">{{item.totalPrice}}</em>
											</div>
										</li>
										<li class="td td-oplist">
											<div class="td-inner">
												<span class="phone-title">配送方式</span>
												<div class="pay-logis">
													<!-- 快递<b class="sys_item_freprice">10</b>元 -->
													包邮
												</div>
											</div>
										</li>

									</ul>
									<div class="clear"></div>

								</div>
						</tr>
						<div class="clear"></div>
					</template>
				

				</div>
			</div>
			<div class="clear"></div>

			<!--含运费小计 -->
			<div class="buy-point-discharge ">
				<p class="price g_price ">
					合计 <span>¥</span><em class="pay-sum">{{order.payment}}</em>
				</p>
			</div>

			<!--信息 -->
			<div class="order-go clearfix">
				<div class="pay-confirm clearfix">
					<div class="box">
						<div tabindex="0" id="holyshit267" class="realPay"><em class="t">实付款：</em>
							<span class="price g_price ">
								<span>¥</span> <em class="style-large-bold-red " id="J_ActualFee">{{order.payment}}</em>
							</span>
						</div>

						<div id="holyshit268" class="pay-address">

							<p class="buy-footer-address">
								<span class="buy-line-title buy-line-title-type">寄送至：</span>
								<span class="buy--address-detail">
									{{id===0?'':addResstableData[addrIndex].receiverAddress}}
								</span>
								</span>
							</p>
							<p class="buy-footer-address">
								<span class="buy-line-title">收货人：</span>
								<span class="buy-address-detail">
									<span class="buy-user">{{id===0?'':addResstableData[addrIndex].receiverName}} </span>
									<span class="buy-phone">{{id===0?'':addResstableData[addrIndex].receiverPhone}}</span>
								</span>
							</p>
						</div>
					</div>

					<div id="holyshit269" class="submitOrder">
						<div class="go-btn-wrap">
							<a class="btn-go" style="margin-left: 10px;" href="#" @click.prevent="cancel">取消订单</a>
							<a id="J_Go" href="#" class="btn-go" tabindex="0" @click.prevent="push" >提交订单</a>
						</div>
					</div>
					<div class="clear"></div>
				</div>
			</div>
			<div class="theme-popover-mask"></div>
			<div class="theme-popover">
		
				<!--标题 -->
				<div class="am-cf am-padding">
					<div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">新增地址</strong> / <small>Add
							address</small></div>
				</div>
				<hr />
		
				<div class="am-u-md-12">
					<form class="am-form am-form-horizontal">
		
						<div class="am-form-group">
							<label for="user-name" class="am-form-label">收货人</label>
							<div class="am-form-content">
								<input type="text" id="user-name" placeholder="收货人" v-model="address.receiverName">
							</div>
						</div>
		
						<div class="am-form-group">
							<label for="user-phone" class="am-form-label">手机号码</label>
							<div class="am-form-content">
								<input id="user-phone" placeholder="手机号必填" type="tel" v-model="address.receiverPhone">
							</div>
						</div>
						<div class="am-form-group">
							<label for="user-address" class="am-form-label">所在地</label>
							<div class="am-form-content address">
								<input type="text" placeholder="省" v-model="address.receiverProvince" > &nbsp;
								<input type="text" placeholder="市" v-model="address.receiverCity"  > &nbsp;
								<input type="text" placeholder="区/县" v-model="address.receiverDistrict"  > &nbsp;
							</div>
							
						</div>
		
						<div class="am-form-group">
							<label for="user-intro" class="am-form-label">详细地址</label>
							<div class="am-form-content">
								<textarea class="" rows="3" id="user-intro" placeholder="输入详细地址" v-model="address.receiverAddress"></textarea>
								<small>100字以内写出你的详细地址...</small>
							</div>
						</div>
		
						<div class="am-form-group">
							<div class="am-u-sm-9 am-u-sm-push-3">
								<a class="am-btn am-btn-danger" @click="save">保存</a>
								<a class="am-btn am-btn-danger" @click="closed">取消</a>
							</div>
						</div>
					</form>
				</div>
			</div>
		
		</div>

		<div class="clear"></div>
	</div>
	</div>
	<div class="footer">
		<div class="footer-hd ">
			<p>
				<a href="# ">燕园科技</a>
				<b>|</b>
				<a href="home.html">商城首页</a>
				<b>|</b>
				<a href="# ">支付宝</a>
				<b>|</b>
				<a href="# ">物流</a>
			</p>
		</div>
		<div class="footer-bd ">
			<p>
				<a href="#">关于燕园</a>
				<a href="# ">合作伙伴</a>
				<a href="# ">联系我们</a>
				<a href="# ">网站地图</a>
			</p>
		</div>
	</div>
	</div>

	<div class="clear"></div>
	<script src="../js/public.js"></script>
	<script>
		let vm2 = new Vue({
			el: '#app2',
			data: {
				addResstableData: [],
				isedit: false, // 是否处于编辑状态
				id: 0,
				addrIndex: '',
				orderDate: [],
				orderNo: '',
				address: {
					receiverName: '',
					receiverPhone: '',
					receiverProvince: '河北省',
					receiverCity: '秦皇岛市',
					receiverDistrict: '海港区',
					receiverAddress: '河北省河北省海港区燕山大学西校区'
				},
				order: ''
			},
			created() {
				this.orderNo = window.localStorage.getItem('orderNo')
				if (!this.orderNo) {
					window.alert('亲，你尚未购买东西，可以去首页选择商品')
					window.location.href="home.html"
				}
				$axios.get(`/order/${this.orderNo}`,
					response => {
						this.order = response.data
						if (this.order) {
							this.getOrderData() 
							this.getData()
						}
					}
				)
			},
			methods: {
				getData() {
					$axios.get('/address',
						response => {
							this.addResstableData = response.data
							if (this.addResstableData.length>0){
								this.addrIndex = this.addResstableData.length-1
								this.id = this.addResstableData[this.addrIndex].id
							}
						}
					)
				},
				getOrderData() {
					console.log(this.orderNo);
					$axios.get(`/order/detail/${this.orderNo}`,
						response => {
							this.orderDate = response.data
						}
					)
				},
				save() {
					if (this.addResstableData.length > 2) {
						window.alert("亲，每个用户只能保留3个收货地址")
						return
					}
					$axios.post(`/address`,
						response => {
							this.closed()
							this.getData()
						}, this.address
					)
				},
				setAddr(id,index) {
					this.addrIndex = index
					this.id = id
				},
				cancel(){
					$axios.put(`/order/cancel/${this.orderNo}`,
						response => {
							window.localStorage.removeItem("orderNo")
							window.alert(response.message)
						}
					)
				},
				push(){
					if (this.id === 0) {
						window.alert("亲，请选择收获地址")
						return
					}
					$axios.put(`/order/payment/${this.orderNo}`,
						response => {
							window.localStorage.removeItem("orderNo")
							window.localStorage.setItem("payNo",response.data)
							window.location.href = "success.html"
						}, {addrId:this.id, payment:this.order.payment}
					)
				},
				closed() {
					$(document.body).css("overflow","visible");
					$('.theme-login').removeClass("selected");
					$('.item-props-can').removeClass("selected");					
					$('.theme-popover-mask').hide();
					$('.theme-popover').slideUp(200);
				}
			}
		})
	</script>
</body>

</html>